package com.ysq.controller;

import com.ysq.controller.result.Result;
import com.ysq.entity.Orders;
import com.ysq.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: OrderController
 * Package: com.ysq.controller
 * Description:
 *
 * @Author YSQ
 * @Create 2023/1/13 13:31
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService service;

    /**
     * 用户端订单支付
     *
     * @param order 接收前端传来的当前用户下单的订单参数
     * @return 返回统一结果封装类
     */
    @PostMapping("/submit")
    public Result<String> submit(@RequestBody Orders order) {
        //先看看前端数据能不能接收到
        log.info(order.toString());
        //调用业务层方法完成对后端数据库表的更新
        boolean flag = service.submit(order);
        //返回结果
        return flag ? Result.success("下单成功~~~") : Result.error("下单失败~~~");
    }
}
